package com.nmgs.common;

import lombok.Data;

/**
 * @author: shuguang
 * @date: 2022年10月16日 16:01
 * @description:  返回结果
 */
@Data
public class Result<T> {
    private String code;
    private String msg;
    private T data;
    private int count;
    public Result() {
    }

    public Result(T data) {
        this.data = data;
    }

    public static Result success() {
        Result result = new Result<>();
        result.setCode(MessageEnum.成功.getCode());
        result.setMsg(MessageEnum.成功.getMessage());
        return result;
    }

    public static <T> Result<T> success(T data) {
        Result<T> result = new Result<>(data);
        result.setCode(MessageEnum.成功.getCode());
        result.setMsg(MessageEnum.成功.getMessage());
        return result;
    }
    public static <T> Result<T> success(T data,int count) {
        Result<T> result = new Result<>(data);
        result.setCode(MessageEnum.成功.getCode());
        result.setMsg(MessageEnum.成功.getMessage());
        result.setCount(count);
        return result;
    }

    public static Result error(String code, String msg) {
        Result result = new Result();
        result.setCode(code);
        result.setMsg(msg);
        return result;
    }
}
